const Base64 = require('js-base64');
const request = require('./request');
const queryString = require('querystring');
module.exports = {
  index: async query => {
    const {songmid, raw} = query;

    if (!songmid) {
      return {
        result: 500,
        errMsg: 'songmid 不能为空',
      };
    }
    let geturl = queryString.stringify({
      songmid,
      pcachetime: new Date().getTime(),
      g_tk: 5381,
      loginUin: 0,
      hostUin: 0,
      inCharset: 'utf8',
      outCharset: 'utf-8',
      notice: 0,
      platform: 'yqq',
      needNewCode: 0,
    });
    const result = await request(
      'http://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg?' + geturl,
    );

    result.lyric = Base64.Base64.decode(result.lyric);
    result.trans = Base64.Base64.decode(result.trans || '');
    if (Number(raw)) {
      return result;
    } else {
      return {
        result: 100,
        data: result,
      };
    }
  },
};
